home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / NPP.PAK / HISTORY.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  95 lines

  1. // history.cpp : implementation of the CHistoryList class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "np.h"
  16. #include "combobar.h"
  17. #include "mainfrm.h"
  18. #include "npdoc.h"
  19. #include "npview.h"
  20. #include "finddlg.h"
  21. #include <afxcoll.h>
  22.  
  23. void CHistoryList::FillCombobox()
  24. {
  25.     CNotepadView* pView = GetApplicationView();
  26.     CWnd* pWnd = pView->m_pFindDialog->GetDlgItem(IDC_COMBO1);
  27.     ASSERT_VALID(pWnd);
  28.         
  29.     POSITION pos = GetHeadPosition();
  30.     while(pos)
  31.         pWnd->SendMessage(CB_ADDSTRING, 0, (LPARAM)((LPCTSTR)GetNext(pos)));
  32. }
  33.  
  34.  
  35. BOOL CHistoryList::AddString(CString &s1)
  36. {
  37.     CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
  38.     CWnd* pWnd = &pFrame->m_wndToolBar.m_toolBarCombo;
  39.     ASSERT_VALID(pWnd);
  40.  
  41.     if (!s1.GetLength())
  42.         return FALSE;
  43.  
  44.     POSITION pos = Find(s1);
  45.     int nCount = GetCount();
  46.  
  47.     if (pos == NULL)
  48.     {
  49.         // if list is full, remove from the end
  50.         if (nCount == HISTORY_COUNT)
  51.         {
  52.             RemoveTail();
  53.             pWnd->SendMessage(CB_DELETESTRING, nCount-1);
  54.         }
  55.  
  56.         AddHead(s1);
  57.         pWnd->SendMessage(CB_INSERTSTRING, 0, (LPARAM)((LPCTSTR)s1));
  58.     }
  59.     else
  60.     {
  61.         SwapStrings(pWnd, s1);
  62.     }
  63.  
  64.     return TRUE;
  65. }
  66.  
  67. void CHistoryList::SwapStrings(CWnd* pWnd, CString &s1)
  68. {
  69.     // swap internal list items
  70.     POSITION pos = GetHeadPosition();    
  71.     ASSERT(pos != NULL);
  72.  
  73.     CString s2;
  74.     int nCount = GetCount();
  75.     int idx=0;
  76.  
  77.     // Note: combo-box find is not case-sensitive
  78.     do
  79.     {
  80.         s2 = GetNext(pos);
  81.     } while(idx < nCount && s1 != s2 && ++idx);
  82.  
  83.  
  84.     // swap internal list
  85.     pos = FindIndex(idx);
  86.     ASSERT(pos != NULL);    
  87.     RemoveAt(pos);
  88.     AddHead(s2);
  89.  
  90.     // swap combo box item with combo's edit control
  91.     pWnd->SendMessage(CB_DELETESTRING, idx);
  92.     pWnd->SendMessage(CB_SETCURSEL, pWnd->SendMessage(CB_INSERTSTRING, 0, (LPARAM)((LPCTSTR)s1)));
  93. }
  94.  
  95.